﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.utils {
    import flash.display.*;
    import flash.geom.*;

    public class GfxUtil {

        public static function bitmapDataInRect(_arg1:BitmapData, _arg2:Rectangle):BitmapData{
            var _local3:BitmapData = new BitmapData(_arg2.width, _arg2.height);
            _local3.copyPixels(_arg1, _arg2, new Point(0, 0));
            return (_local3);
        }
        public static function copyPixelsTiled(_arg1:BitmapData, _arg2:BitmapData, _arg3:Rectangle, _arg4:Rectangle):void{
            var _local6:*;
            var _local5:Point = _arg4.topLeft.clone();
            do  {
                _local6 = _arg1.rect.clone();
                if ((_local5.y + _local6.height) > _arg4.height){
                    _local6.height = (_local6.height - ((_local6.height + _local5.y) - _arg4.bottom));
                };
                do  {
                    if ((_local5.x + _local6.width) > _arg4.right){
                        _local6.width = (_local6.width - ((_local6.width + _local5.x) - _arg4.right));
                    };
                    _arg2.copyPixels(_arg1, _local6, _local5, null, null, true);
                    _local5.offset(_arg1.width, 0);
                } while (_local5.x < _arg4.width);
                _local5.offset(0, _arg1.height);
                _local5.x = _arg4.topLeft.x;
            } while (_local5.y < _arg4.height);
        }
        public static function drawRect(_arg1:Sprite, _arg2:Number, _arg3:Number, _arg4:Number, _arg5:Number):void{
            _arg1.graphics.drawRect(_arg2, _arg3, _arg4, _arg5);
        }
        public static function segmentedBitmapsOfScale9RectInRectWithSize(_arg1:BitmapData, _arg2:Rectangle):Object{
            var _local5:Rectangle;
            var _local6:String;
            var _local7:BitmapData;
            var _local3:Object = segmentedRectsOfScale9RectInRectWithSize(_arg2, _arg1.width, _arg1.height);
            var _local4:Object = {};
            for (_local6 in _local3) {
                _local5 = Rectangle(_local3[_local6]);
                _local7 = new BitmapData(_local5.width, _local5.height, true, 0);
                _local7.copyPixels(_arg1, _local5, new Point(0, 0));
                _local4[_local6] = _local7;
            };
            return (_local4);
        }
        public static function drawRoundRect(_arg1:Sprite, _arg2:Number, _arg3:Number, _arg4:Number, _arg5:Number, _arg6:Array):void{
            var _local7:Number;
            var _local8:Number;
            var _local9:Number;
            var _local10:Number;
            switch (_arg6.length){
                case 1:
                    _local10 = _arg6[0];
                    _local9 = _local10;
                    _local8 = _local9;
                    _local7 = _local8;
                    break;
                case 2:
                    _local7 = _arg6[0];
                    _local9 = _local7;
                    _local8 = _arg6[1];
                    _local10 = _local8;
                    break;
                case 3:
                    _local9 = _arg6[0];
                    _local7 = _arg6[1];
                    _local10 = _local7;
                    _local8 = _arg6[2];
                    break;
                case 4:
                    _local9 = _arg6[0];
                    _local10 = _arg6[1];
                    _local7 = _arg6[2];
                    _local8 = _arg6[3];
                    break;
                default:
                    log("w Wrong number of parameters (radius) in drawRoundRect!");
                    return;
            };
            _arg1.graphics.drawRoundRectComplex(_arg2, _arg3, _arg4, _arg5, _local9, _local10, _local8, _local7);
        }
        public static function drawWedge(_arg1:Graphics, _arg2:Number, _arg3:Number, _arg4:Number, _arg5:Number, _arg6:Number, _arg7:Number=-1):void{
            var _local8:Number;
            var _local9:Number;
            var _local10:Number;
            var _local11:Number;
            var _local12:Number;
            var _local13:Number;
            var _local14:Number;
            var _local15:Number;
            var _local16:Number;
            var _local17:Number;
            var _local18:Number;
            var _local19:Number;
            if (_arg7 == -1){
                _arg7 = _arg6;
            };
            _arg1.moveTo(_arg2, _arg3);
            if (Math.abs(_arg5) > 360){
                _arg5 = 360;
            };
            _local12 = Math.ceil((Math.abs(_arg5) / 45));
            _local8 = (_arg5 / _local12);
            _local9 = (-((_local8 / 180)) * Math.PI);
            _local10 = (-((_arg4 / 180)) * Math.PI);
            if (_local12 > 0){
                _local13 = (_arg2 + (Math.cos(((_arg4 / 180) * Math.PI)) * _arg6));
                _local14 = (_arg3 + (Math.sin(((-(_arg4) / 180) * Math.PI)) * _arg7));
                _arg1.lineTo(_local13, _local14);
                _local19 = 0;
                while (_local19 < _local12) {
                    _local10 = (_local10 + _local9);
                    _local11 = (_local10 - (_local9 / 2));
                    _local15 = (_arg2 + (Math.cos(_local10) * _arg6));
                    _local16 = (_arg3 + (Math.sin(_local10) * _arg7));
                    _local17 = (_arg2 + (Math.cos(_local11) * (_arg6 / Math.cos((_local9 / 2)))));
                    _local18 = (_arg3 + (Math.sin(_local11) * (_arg7 / Math.cos((_local9 / 2)))));
                    _arg1.curveTo(_local17, _local18, _local15, _local16);
                    _local19++;
                };
                _arg1.lineTo(_arg2, _arg3);
            };
        }
        public static function bitmapDataScaledToRect(_arg1:BitmapData, _arg2:Rectangle, _arg3:Boolean=true, _arg4:Boolean=false):BitmapData{
            var _local5:Rectangle = new Rectangle(0, 0, _arg1.width, _arg1.height);
            GeomUtil.scaleRectToRect(_local5, _arg2, _arg3, _arg4);
            var _local6:Matrix = new Matrix();
            _local6.scale((_local5.width / _arg1.width), (_local5.height / _arg1.height));
            var _local7:BitmapData = new BitmapData(_local5.width, _local5.height, true, 0);
            _local7.draw(_arg1, _local6, null, null, null, true);
            return (_local7);
        }
        public static function drawCircle(_arg1:Sprite, _arg2:Number, _arg3:Number, _arg4:Number):void{
            _arg1.graphics.drawCircle(_arg2, _arg3, _arg4);
        }
        public static function drawStar(_arg1:Sprite, _arg2:Number, _arg3:Number, _arg4:int, _arg5:Number, _arg6:Number, _arg7:Number=NaN):void{
            var _local9:Number;
            var _local8:Number = ((2 * Math.PI) / _arg4);
            var _local10:int;
            if (isNaN(_arg7)){
                _arg7 = (-(_local8) + (Math.PI / 2));
            } else {
                _arg7 = (_arg7 * (Math.PI / 180));
            };
            _arg2 = (_arg2 + _arg6);
            _arg3 = (_arg3 + _arg6);
            var _local11:int;
            while (_local11 < _arg4) {
                var _temp1 = _local10;
                _local10 = (_local10 + 1);
                _local9 = ((_local8 * _temp1) + _arg7);
                if (_local11 == 0){
                    _arg1.graphics.moveTo(((Math.cos(_arg7) * _arg5) + _arg2), ((Math.sin(_arg7) * _arg5) + _arg3));
                } else {
                    _arg1.graphics.lineTo(((Math.cos(_local9) * _arg5) + _arg2), ((Math.sin(_local9) * _arg5) + _arg3));
                };
                _local9 = (_local9 + (_local8 / 2));
                _arg1.graphics.lineTo(((Math.cos(_local9) * _arg6) + _arg2), ((Math.sin(_local9) * _arg6) + _arg3));
                _local11++;
            };
            _arg1.graphics.lineTo(((Math.cos(_arg7) * _arg5) + _arg2), ((Math.sin(_arg7) * _arg5) + _arg3));
        }
        public static function segmentedRectsOfScale9RectInRectWithSize(_arg1:Rectangle, _arg2:Number, _arg3:Number):Object{
            var _local4:Object = {};
            _local4.tl = new Rectangle(0, 0, _arg1.left, _arg1.top);
            _local4.t = new Rectangle(_arg1.left, 0, _arg1.width, _arg1.top);
            _local4.tr = new Rectangle(_arg1.right, 0, (_arg2 - _arg1.right), _arg1.top);
            _local4.r = new Rectangle(_arg1.right, _arg1.top, (_arg2 - _arg1.right), _arg1.height);
            _local4.br = new Rectangle(_arg1.right, _arg1.bottom, (_arg2 - _arg1.right), (_arg3 - _arg1.bottom));
            _local4.b = new Rectangle(_arg1.left, _arg1.bottom, _arg1.width, (_arg3 - _arg1.bottom));
            _local4.bl = new Rectangle(0, _arg1.bottom, _arg1.left, (_arg3 - _arg1.bottom));
            _local4.l = new Rectangle(0, _arg1.top, _arg1.left, _arg1.height);
            _local4.c = new Rectangle(_arg1.left, _arg1.top, _arg1.width, _arg1.height);
            return (_local4);
        }
        public static function drawDashedLine(_arg1:Sprite, _arg2:Number, _arg3:Number, _arg4:Number, _arg5:Number, _arg6:Number, _arg7:Number):void{
            var _local8:Number;
            var _local9:Number;
            var _local10:Number;
            var _local11:Number;
            var _local12:Number;
            var _local13:Number;
            _local8 = (_arg6 + _arg7);
            _local9 = (_arg4 - _arg2);
            _local10 = (_arg5 - _arg3);
            var _local14:Number = Math.sqrt(((_local9 * _local9) + (_local10 * _local10)));
            _local11 = Math.floor(Math.abs((_local14 / _local8)));
            var _local15:Number = Math.atan2(_local10, _local9);
            var _local16:Number = Math.cos(_local15);
            var _local17:Number = Math.sin(_local15);
            _local12 = _arg2;
            _local13 = _arg3;
            _local9 = (_local16 * _local8);
            _local10 = (_local17 * _local8);
            if (_local11){
                while (_local11--) {
                    _arg1.graphics.moveTo(_local12, _local13);
                    _arg1.graphics.lineTo((_local12 + (_local16 * _arg6)), (_local13 + (_local17 * _arg6)));
                    _local12 = (_local12 + _local9);
                    _local13 = (_local13 + _local10);
                };
                _arg1.graphics.moveTo(_local12, _local13);
                _local14 = Math.sqrt((((_arg4 - _local12) * (_arg4 - _local12)) + ((_arg5 - _local13) * (_arg5 - _local13))));
                if (_local14 > _arg6){
                    _arg1.graphics.lineTo((_local12 + (_local16 * _arg6)), (_local13 + (_local17 * _arg6)));
                } else {
                    if (_local14 > 0){
                        _arg1.graphics.lineTo((_local12 + (_local16 * _local14)), (_local13 + (_local17 * _local14)));
                    };
                };
                _arg1.graphics.moveTo(_arg4, _arg5);
            };
        }
        public static function pixelateBitmap(_arg1:BitmapData, _arg2:Number, _arg3:Number):BitmapData{
            var _local4:BitmapData = new BitmapData((_arg1.width / _arg2), (_arg1.height / _arg2), true, _arg3);
            var _local5:Matrix = new Matrix();
            _local5.scale((1 / _arg2), (1 / _arg2));
            _local4.draw(_arg1, _local5);
            var _local6:BitmapData = new BitmapData(_arg1.width, _arg1.height, true, _arg3);
            _local5 = new Matrix();
            _local5.scale(_arg2, _arg2);
            _local6.draw(_local4, _local5);
            return (_local6);
        }
        public static function copyScaledPixels(_arg1:BitmapData, _arg2:BitmapData, _arg3:Rectangle, _arg4:Point, _arg5:Point, _arg6:Boolean=false):void{
            var _local7:BitmapData = new BitmapData(_arg3.width, _arg3.height, _arg1.transparent, 0);
            _local7.copyPixels(_arg1, _arg3, new Point(0, 0));
            var _local8:BitmapData = new BitmapData((_arg3.width * _arg5.x), (_arg3.height * _arg5.y), _arg1.transparent, 0);
            var _local9:Matrix = new Matrix();
            _local9.scale(_arg5.x, _arg5.y);
            _local8.draw(_local7, _local9, null, null, null, _arg6);
            _arg2.copyPixels(_local8, _local8.rect, _arg4, null, null, true);
        }
        public static function scale9Bitmap(_arg1:BitmapData, _arg2:BitmapData, _arg3:Rectangle):void{
            var _local4:Point = new Point(_arg3.x, _arg3.y);
            var _local5:Point = new Point(((_arg1.width - _arg3.x) - _arg3.width), ((_arg1.height - _arg3.y) - _arg3.height));
            var _local6:Point = new Point((((_arg2.width - _arg3.x) - _local5.x) / _arg3.width), (((_arg2.height - _arg3.y) - _local5.y) / _arg3.height));
            _arg2.copyPixels(_arg1, new Rectangle(0, 0, _arg3.x, _arg3.y), new Point(0, 0), null, null, true);
            _arg2.copyPixels(_arg1, new Rectangle(_arg3.right, 0, _local5.x, _arg3.y), new Point((_arg2.width - _local5.x), 0), null, null, true);
            _arg2.copyPixels(_arg1, new Rectangle(_arg3.right, _arg3.bottom, _local5.x, _local5.y), new Point((_arg2.width - _local5.x), (_arg2.height - _local5.y)), null, null, true);
            _arg2.copyPixels(_arg1, new Rectangle(0, _arg3.bottom, _arg3.x, _local5.y), new Point(0, (_arg2.height - _local5.y)), null, null, true);
            copyScaledPixels(_arg1, _arg2, new Rectangle(_local4.x, 0, _arg3.width, _local4.y), new Point(_arg3.x, 0), new Point(_local6.x, 1));
            copyScaledPixels(_arg1, _arg2, new Rectangle(_arg3.right, _local4.y, _local5.x, _arg3.height), new Point((_arg2.width - _local5.x), _local4.y), new Point(1, _local6.y));
            copyScaledPixels(_arg1, _arg2, new Rectangle(_local4.x, _arg3.bottom, _arg3.width, _local5.y), new Point(_arg3.x, (_arg2.height - _local5.y)), new Point(_local6.x, 1));
            copyScaledPixels(_arg1, _arg2, new Rectangle(0, _local4.y, _local4.x, _arg3.height), new Point(0, _arg3.y), new Point(1, _local6.y));
            copyScaledPixels(_arg1, _arg2, _arg3, _local4, _local6);
        }

    }
}//package reprise.utils 
